<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        编辑报价单
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../../lib/loading/okLoading.js"></script>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="../../../../lib/layui/css/layui_2.5.7.css">

</head>
<!--借还流水-->
<style>
    .layui-form-label {
        width: 150px !important;
    }

    .formtype{
        margin-top: 20px;
        margin-bottom: 20px;
    }

    .onetype{
        margin-left: 3%;
    }

    .latype{
        margin-left: 3%;
    }
</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <input  autocomplete="off"  type="hidden" name="id" id="id" >


                <div class="layui-form-item" id="selectpro" style="margin-left: 3%;">
                    <label class="layui-form-label"> <span class='x-red'>*</span>选择关联项目</label>
                    <div style="width: 65%" class="layui-input-inline">
                        <button @click="xzglxm" style="width: auto;height: auto;margin-top: 1%;margin-left: 20px;" type="button"
                                class="btn btn-info  btn-xs">
                            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                            选择关联项目
                        </button>

                    </div>
                </div>

                <div class="layui-form-item formtype" id="selectproMsg">
                    <label class="layui-form-label onetype">甲方名称</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="hidden" name="fistIdss" placeholder="甲方（需方）id" v-model="projectData.customerId" class="layui-input" disabled='disabled'>
                        <input  autocomplete="off"  type="text" name="fistNamess"v-model="projectData.customerName" placeholder="甲方名称" class="layui-input" disabled='disabled'>
                    </div>

                    <label class="layui-form-label latype">项目名称</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="hidden" name="projectIdss" placeholder="项目 id" v-model="projectData.id" class="layui-input" disabled='disabled'>
                        <input  autocomplete="off"  type="text" name="projectNamess"   v-model="projectData.name" placeholder="项目名称" class="layui-input" disabled='disabled' >
                    </div>
                </div>

                <div class="layui-form-item formtype" id="twos">
                    <label class="layui-form-label onetype">甲方名称</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="fistName" id="fistName" v-model="kfQuotationData.fistName" placeholder="甲方名称" class="layui-input" disabled='disabled'>
                    </div>

                    <label class="layui-form-label latype">项目名称</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="projectName" id="projectName"  v-model="kfQuotationData.projectName" placeholder="项目名称" class="layui-input" disabled='disabled' >
                    </div>
                </div>

                <div class="layui-form-item formtype">
                    <label class="layui-form-label onetype">乙方名称</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="requestUser" v-model="kfQuotationData.secondName" placeholder="乙方名称" class="layui-input" disabled='disabled'>
                    </div>

                    <label class="layui-form-label latype">报价人</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="requestDepartment" v-model="kfQuotationData.quotationName" placeholder="报价人" class="layui-input" disabled='disabled'>
                    </div>
                </div>

                <div class="layui-form-item formtype">
                    <label class="layui-form-label onetype">审批人员</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="approver" v-model="kfQuotationData.approver" placeholder="审批人员" class="layui-input" disabled='disabled'>
                    </div>

                    <label class="layui-form-label latype">报价时间</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="requestTime" v-model="kfQuotationData.submitTime" placeholder="申请时间" class="layui-input" disabled='disabled'>
                    </div>
                </div>

                <div class="layui-form-item formtype">
                    <label class="layui-form-label onetype">审批状态</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="typeName" v-model="kfQuotationData.typeName" placeholder="审批状态" class="layui-input" disabled='disabled'>
                    </div>

                    <input  autocomplete="off"  type="hidden" name="partsoutTypeName" id="partsoutTypeName" v-model="kfQuotationData.partsoutType" placeholder="出库状态" class="layui-input" disabled='disabled'>

                    <label class="layui-form-label latype">出库状态</label>
                    <div style="width: 30%" class="layui-input-inline">
                        <select id="partsoutType" name="partsoutType" class="partsoutType" lay-search="" v-model="kfQuotationData.partsoutType">
                        </select>
                    </div>
                </div>

                <div class="layui-form-item formtype">
                    <label class="layui-form-label onetype">备注信息</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="remake" id="remake" v-model="kfQuotationData.remake" placeholder="备注信息" class="layui-input" >
                    </div>
                    <label class="layui-form-label onetype">账单状态</label>
                    <div style="width: 30%"  class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="typeName" v-model="kfQuotationData.priceTypeName" placeholder="账单状态" class="layui-input" disabled='disabled'>
                    </div>
                </div>

                <div style="text-align: center;margin-left: -5%;margin-top: 50px;" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>

                <div style="height:20px;"></div>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="../../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../../js/pub.js"></script>
<script src="../../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../../js/vue.min.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })
</script>
<script>
    let recordId = getQueryVariable("id");
    let deType= getQueryVariable("deType");
    var vm = new Vue({
        el: "#app",
        data: {
            recordId,
            kfQuotationData: null,
            kfBuyPartsList: null,
            projectData:{}
        },
        mounted() {
            let request = {
                url: 'kf/quotation/getQuotationByid',
                data: {
                    userId: $userId,
                    id: recordId
                },
                method: "GET",
            }
            sendRequest(request, (res) => {
                this.kfQuotationData = res.data.kfQuotationData
                this.kfBuyPartsList = res.data.kfBuyPartsList
            });
        },
        methods: {
            xzglxm(){
                layer.open({
                    title: '选择关联项目',
                    type: 2,
                    btnAlign: 'c',
                    area: ['80%', '80%'],
                    content: '../requestform/requestform_select_project.html',
                    end: (i, layero) => {
                        let cp = JSON.parse(localStorage.getItem("requestform_select_project"))
                        this.projectData = cp[0];
                        if(this.projectData !== ""){
                            $("#twos").hide();
                            $("#selectproMsg").show();
                        }
                        layer.close(i);
                    },

                });
            }


        },
    });

    layui.use(['laydate', 'form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;

            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = recordId;
                    form.projectId = $( "input[name='projectIdss']").val() ;
                    form.projectName = $( "input[name='projectNamess']").val() ;
                    form.fistId = $( "input[name='fistIdss']").val() ;
                    form.fistName = $( "input[name='fistNamess']").val() ;
                    let request = {
                        url: 'kf/quotation/editQuotation',
                        data: form,
                        method: "POST",
                    };

                    console.log(request);
                    sendRequest(request, (data) => {
                        console.log(data);
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    let index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();
                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });
        });

    setTimeout(() => {
        let form = layui.form;
        let request = {
            url: 'kf/dictionary/getValue',
            data: {
                userId: $userId,
                dictionaryCode: 'partsout_type'
            },
            method: "GET",
        };
        sendRequest(request, (res) => {
            let d = res.data;
            let a = document.getElementById("partsoutTypeName").value
            $.each(d, function (index, item) {
                let opt;

                if(item.type === a){
                    opt = $("<option value=" + item.type + " selected>" + item.name + "</option>");
                }else{
                    opt = $("<option value=" + item.type + ">" + item.name + "</option>");
                }
                $("select[name=partsoutType]").append(opt);
            });
            form.render('select');
        });
        if(deType === "1"){
            $("#selectpro").hide()
            $("#selectproMsg").hide()
            const cObj12 = document.getElementById("remake");
            cObj12.setAttribute("disabled",'disabled');
            const cObj = document.getElementById("partsoutType");
            cObj.setAttribute("disabled",'disabled');
        }else{
            $("#selectproMsg").hide()
            const cObj = document.getElementById("partsoutType");
            cObj.setAttribute("disabled",'disabled');
        }

    }, 300)

</script>

</body>

</html>
